package com.neusoft.elmboot.controller;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.Point;
import com.neusoft.elmboot.service.PointService;

@RestController
@RequestMapping("/points")
@CrossOrigin
public class PointController {

    @Autowired
    PointService pointService; // 假设服务类名也从IntegralService改为PointService

    @PostMapping("/{userId}")
    public int savePoint(@PathVariable String userId) throws Exception {
        return pointService.savePoint(userId);
    }

    @GetMapping("/{userId}")
    public Point getPointByUserid(@PathVariable String userId) throws Exception {
        return pointService.getPointByUserid(userId);
    }

    // @PutMapping("/{userId}")
    // public int updatePointCount(@PathVariable String userId, @RequestBody BigDecimal count) throws Exception {
    //     return pointService.updatePointCount(userId, count);
    // }

    @PostMapping("/add")
    public String addPoints(@RequestParam String type, @RequestParam String userId, @RequestParam BigDecimal amount) {
        pointService.addPoints( userId, amount,type);
        return "积分添加成功";
    }

    @PostMapping("/use")
    public int usePoint(String userId, BigDecimal count) {
        return pointService.usePoint(userId, count);
    }
}